/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.uch.syscom.utils;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;
import pe.edu.uch.syscom.mapping.TbUsuario;

/**
 *
 * @author Jose Tejada
 */
public class CommonWeb {

    private static ActionEvent m_event;

    public static TbUsuario getUsuarioSesion() {
        ExternalContext ec;
        HttpSession session;
        TbUsuario usuarioSesion;

        ec = FacesContext.getCurrentInstance().getExternalContext();
        session = (HttpSession) ec.getSession( false );
        usuarioSesion = (TbUsuario) session.getAttribute( "usuario" );

        return usuarioSesion;
    }

    public static void setUsuarioSesion( TbUsuario usuario ) {
        ExternalContext ec;
        HttpSession session;

        ec = FacesContext.getCurrentInstance().getExternalContext();
        session = (HttpSession) ec.getSession( false );
        session.setAttribute( "usuario", usuario );
    }

    public static String getParamFromUI( String sNomParam ) {
        String sParam;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            sParam = context.getExternalContext().getRequestParameterMap().get( sNomParam );
        } catch ( Exception ex ) {
            sParam = "";
            ex.printStackTrace();
        }
        return sParam;
    }

    public static String getCatDesc( String sCodigo ) {
        return CommonDAO.getTbCatalogoDAO().getDescripcion( sCodigo );
    }
}
